package com.eedi.framework.dict.dal.mapper;

import com.eedi.framework.dict.controller.sys.vo.type.SysDictTypePageReq;
import com.eedi.framework.common.pojo.PageResult;
import com.eedi.framework.mybatis.core.mapper.BaseMapperX;
import com.eedi.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.eedi.framework.dict.dal.dataobject.SysDictTypeDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

@Mapper
public interface SysDictTypeMapper extends BaseMapperX<SysDictTypeDO> {

    default PageResult<SysDictTypeDO> selectPage(SysDictTypePageReq reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SysDictTypeDO>()
                .likeIfPresent(SysDictTypeDO::getSysDictName, reqVO.getSysDictName())
                .likeIfPresent(SysDictTypeDO::getSysDictDataType, reqVO.getSysDictDataType())
                .eqIfPresent(SysDictTypeDO::getSysDictDataStatus, reqVO.getSysDictDataStatus())
                .betweenIfPresent(SysDictTypeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SysDictTypeDO::getSysDictTypeId));
    }

    default SysDictTypeDO selectByType(String type) {
        return selectOne(SysDictTypeDO::getSysDictDataType, type);
    }

    default SysDictTypeDO selectByName(String name) {
        return selectOne(SysDictTypeDO::getSysDictName, name);
    }

    @Update("UPDATE sys_dict_type SET deleted = 1, deleted_time = #{deletedTime} WHERE sys_dict_type_id = #{sysDictTypeId}")
    void updateToDelete(@Param("sysDictTypeId") String sysDictTypeId, @Param("deletedTime") LocalDateTime deletedTime);

}
